<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!-- 搜索 -->
      <el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="initMethod"/>
      <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
        <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
      </el-select>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="initMethod">搜索</el-button>
      <!-- 新增 -->
      <!--<div style="display: inline-block;margin: 0px 2px;">-->
      <!--<el-button v-permission="['admin','identity:add']" class="filter-item" size="mini" type="primary" icon="el-icon-plus" @click="add">新增</el-button>-->
      <!--</div>-->
    </div>
    <!--表单组件-->
    <!--<eForm ref="form" :is-add="isAdd" :list="tableData.entity"/>-->
    <!--表格渲染-->
    <el-table v-loading="loading" :data="tableData.entity" stripe border size="small" style="width: 100%;">
      <el-table-column prop="id" label="商铺ID"/>
      <el-table-column prop="agentId" label="代理ID"/>
      <el-table-column prop="shopName" label="商户名称" show-overflow-tooltip/>
      <el-table-column prop="name" label="代理姓名" width="95px"/>
      <el-table-column prop="openid" label="商家openID" show-overflow-tooltip/>
      <el-table-column prop="telphone" label="联系电话" width="95px" show-overflow-tooltip/>
      <el-table-column prop="commission" label="提成比例"/>
      <el-table-column prop="count" label="设备数"/>
      <el-table-column prop="amount" label="累计金额"/>
      <el-table-column prop="orderCount" label="订单数"/>
      <el-table-column prop="address" label="详细地址" show-overflow-tooltip/>
      <el-table-column label="工作人员信息" align="center">
        <el-table-column prop="salesmanId" label="业务人员" show-overflow-tooltip/>
        <el-table-column prop="salesmanCommission" label="业务提成"/>
        <el-table-column prop="engId" label="安装人员" show-overflow-tooltip/>
        <el-table-column prop="engCommission" label="安装提成"/>
      </el-table-column>
      <el-table-column prop="created" label="创建时间" show-overflow-tooltip/>
      <el-table-column label="操作" fixed="right" width="150px" align="center">
        <template slot-scope="scope">
          <!--<el-button size="mini" type="primary" icon="el-icon-edit" @click="edit(scope.row.account)"/>-->
          <!--<el-popover v-permission="['admin','identity:del']" :ref="scope.row.id" placement="top" width="180">
            <p>确定删除该商铺吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
              <el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.id)">确定</el-button>
            </div>
            <el-button slot="reference" type="danger" icon="el-icon-delete" size="mini"/>
          </el-popover>-->
          <el-tooltip slot="reference" content="订单详情" placement="top">
            <el-button type="primary" size="mini" icon="el-icon-document-copy" @click="orderDetail(scope.row.id)"/>
          </el-tooltip>
          <el-tooltip slot="reference" content="所有设备" placement="top">
            <el-button type="success" size="mini" icon="el-icon-cpu" @click="deviceDetail(scope.row.id)"/>
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <div class="block">
      <el-pagination
        :current-page="query.page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="query.size"
        :total="tableData.total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
// import eForm from './form'
import { postRequest } from '@/api/identity'
export default {
  // components: { eForm },
  data() {
    return {
      loading: false,
      delLoading: false,
      // isAdd: false,
      query: {
        value: '',
        type: '',
        page: 1,
        size: 10
      },
      tableData: {
        total: 0,
        data: []
      },
      queryTypeOptions: [
        { key: 'shopId', display_name: '商铺ID' },
        { key: 'shopName', display_name: '商铺名称' },
        { key: 'agentId', display_name: '代理ID' },
        { key: 'agentName', display_name: '代理名称' }
      ]
    }
  },
  created() {
    if (Object.keys(this.$route.query).length !== 0) {
      this.query.value = this.$route.query.value
      this.query.type = this.$route.query.type
    }
    this.$nextTick(() => {
      this.initMethod()
    })
  },
  methods: {
    checkPermission,
    initMethod() {
      postRequest('/pc/shop', this.query).then(resp => {
        console.log(resp)
        this.tableData = resp.data
      })
    },
    handleSizeChange(val) {
      this.query.size = val
      this.initMethod()
    },
    handleCurrentChange(val) {
      this.query.page = val
      this.initMethod()
    },
    orderDetail(id) {
      this.$router.push({ path: 'order', query: { value: id, type: 'shopid' }})
    },
    deviceDetail(id) {
      this.$router.push({ path: 'device', query: { value: id, type: 'shopId' }})
    }
    // add() {
    //   this.isAdd = true
    //   this.$refs.form.dialog = true
    // },
    // edit(val) {
    //   this.isAdd = false
    //   const _this = this.$refs.form
    //   _this.form = val
    //   _this.dialog = true
    //   _this.initMethods()
    // }
  }
}
</script>

<style scoped>
  .el-button + .el-button {
    margin-left: 0;
  }
</style>
